﻿using System;
using CompactMapper.Orm.Annotations;
using CompactMapper.Orm.UnitOfWork.Mappings.Meta.PropertyInfos;
using CompactMapper.Orm.UnitOfWork.Mappings.Meta.PropertyInfos.Columns;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CompactMapper.Orm.Tests.Columns
{
    [TestClass]
    public class CharEnumerationMappingTests : OrmInMemoryTest
    {
        [Table]
        public class TableWithCharColumn
        {
            public class CharEnumeration : Enumerations.Enumeration<String>
            {
                public const string TheValue = "TheValue";
                public static CharEnumeration CharEnumerationValue = new CharEnumeration();

                private CharEnumeration() : base(TheValue) { }
            }

            [CharColumn]
            public CharEnumeration CharEnumerationColumn { get; set; }
        }



        [TestMethod]
        public void CharEnumerationMappingTests_FromSql()
        {
            var propertyInfo = typeof(TableWithCharColumn).GetProperty("CharEnumerationColumn");
            var column = new TextColumn(new PropertyInfoPersistenceAttributePair(propertyInfo, new CharColumnAttribute()));

            const string nullString = null;
            var emptyString = String.Empty;
            const string invalidString = "invalidString";
            const string validString = TableWithCharColumn.CharEnumeration.TheValue;

            Assert.IsNull(column.FromSqLiteObject(DBNull.Value));
            Assert.IsNull(column.FromSqLiteObject(nullString));
            Assert.IsNull(column.FromSqLiteObject(emptyString));
            Assert.IsNull(column.FromSqLiteObject(invalidString));
            Assert.IsNotNull(column.FromSqLiteObject(validString));

        }
    }
}
